﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace NCAB.WF
{
    public partial class Home : System.Web.UI.Page
    {
        private MembershipUser user;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Session["update"] = Server.UrlEncode(System.DateTime.Now.ToString());
            }

            if (Request.IsAuthenticated && Membership.GetUser() != null)
            {
                user = Membership.GetUser();

                services.WS_User ws = new services.WS_User();
                SP_S_aspnet_UserExtraInfoResult usuario = JsonConvert.DeserializeObject<SP_S_aspnet_UserExtraInfoResult>(ws.GetUsuario_ByUserName(user.UserName, ConfigurationManager.AppSettings["WSUser"], ConfigurationManager.AppSettings["WSPass"]));

                lbMensajeBienvenida.Text = "Bienvenido " + usuario.Nombres.Split(' ')[0];
                ScriptManager.RegisterStartupScript(this, GetType(), "scriptWelcome", "notificacion('success', '" + usuario.Nombres + " " + usuario.Apellidos + "', '¡Bienvenido!');", true);
            }
            else
            {
                Response.Redirect("Default.aspx");
            }
        }

        void Page_PreRender(object obj, EventArgs e)
        {
            ViewState["update"] = Session["update"];
        }
    }
}